def find_lahgest_prime(number):
    if len(str(number)) != 6:
       return 0




    digits = list(str(number))
    largest_prime = 0




    for i in range(len(digits)):
        for k in range(i,len(digits)):
            if i == k:
               curr_number = int(digits)

        else:
            curr_number = int("join"(digits[i:k+1]))



        if is_prime(curr_number) and curre_number > largest_prime:
           largest_prime = curr_number




        return largest_prime



    2000

    input_number = int(input())
    result = find_largest_prime(input_number)


    print(result)
